package com.jastar.android.game.richman.logic.handler;

import com.jastar.android.game.richman.GameActivity;
import com.jastar.android.game.richman.logic.bean.Cell;
import com.jastar.android.game.richman.logic.bean.Player;
import com.jastar.android.game.richman.logic.enums.CellType;
import com.jastar.android.game.richman.logic.enums.LandType;
import com.jastar.android.util.Alert;

public class CellLandHandler extends CellDefaultHandler {


    @Override
    public void hand(GameActivity activity, Cell c, Player p, CellType.Callback callback) {
        if (null == c.getOwner()) {
            if (p.getMoney() >= c.getPrice()) {
                Alert.select(activity, p.getIcon(), "是否购买？", (d, w) -> {
                    switch (w) {
                        case 0: //住宅房
                            p.buy(c, LandType.HOUSE);
                            break;
                        case 1: //连锁店
                            p.buy(c, LandType.CHAIN);
                            break;
                        default:
                    }
                    callback.callback();
                }, "购买住宅房", "购买连锁店", "不购买");
            } else {
                Alert.info(activity, p.getIcon(), "现金不足，不能购买。", "确定", null);
                callback.callback();
            }
        } else if (!c.getOwner().equals(p)) {
            Alert.info(activity, p.getIcon(), String.format("支付路费：$%d", c.getToll()), "支付", (d, w) -> {
                p.pay(c.getToll());
                c.getOwner().receive(c.getToll());
                callback.callback();
            });
        } else if (!c.isMaxLevel()) {
            if (p.getMoney() >= c.getPrice()) {
                Alert.confirm(activity, p.getIcon(), String.format("是否升级建筑？"), "升级", (d, w) -> {
                    p.pay(c.getPrice());
                    c.levelup();
                    callback.callback();
                }, (d, w) -> callback.callback());
            } else {
                Alert.info(activity, p.getIcon(), "现金不足，不能升级。", "确定", null);
                callback.callback();
            }
        } else {
            Alert.info(activity, p.getIcon(), String.format("已是最高级."), "确定", null);
            callback.callback();
        }
    }

}
